home *** CD-ROM | disk | FTP | other *** search
- On Thu, 2 Feb 1995, Mike Crowl wrote:
-
- > Giday all,
- >
- > just looking for some help in writing a tetris game. The bit I'd like
- > some help with is how you would check to see if the block had hit another
- > block and so on.
- >
- > Any help would be much appreciated.
- >
- > Ben Crowl
-
- Gday Ben (and all you others)
-
- First of all I would like to issue a disclaimer :) It is
- semester one exma week at my university and I last went to bed 4 days
- ago, so forgive any minor errors in my code.
-
- OK. To drop pieces in Tetris, an array thje size of the playing
- area is created eg 11*25 (X*Y). This 2-dimensional array is filled with
- zeros to represnt no pieces. When a piece enters thje playing area, the
- area it occupies is filled with (for example) 1.
-
- A lovely ascii diagram will help here.
-
- 1. No pieces
- 2. L-shape just entering
- 3. L-shape a few moves on
- 4. L-shape after hitting the bottom
- 5. Square almost at the bottom
- 6. Square colliding with L-shape
-
- grid is 8*9 in this example
-
- 1. 00000000 2. 00200000 3. 00000000 4. 00000000 5. 00000000 6. 00000000
- 00000000 00222000 00200000 00000000 00000000 00000000
- 00000000 00000000 00200000 00000000 00000000 00000000
- 00000000 00000000 00222000 00000000 00000000 00000000
- 00000000 00000000 00000000 00000000 00000000 00000000
- 00000000 00000000 00000000 00000000 00001100 00000000
- 00000000 00000000 00000000 00200000 00201100 00201100
- 00000000 00000000 00000000 00200000 00200000 00201100
- 00000000 00000000 00000000 00222000 00222000 00222000
-
- The number 2 represents the code for the l-shape
- The number 1 represents the code for the square
-
- By now you will probably have realised how it all works. But I shall
- explain for the hard of thinking :)
-
- Before a piece drops, its new position in the array is calculated. If
- this collides with any other numbers then the piece is stuck. It has hit
- the bottom.
-
- A way for calculating collisions (just appeared off the top of my head)
- is to calculate a checksum for each horizontal line before and after the
- move. If the 'After move' sum is different to the 'Before move' sum then
- subtract the id code of the current piece (unless the piece is a square
- then subtract 2*id code). If the answer is different to the 'Before sum'
- no, then the new piece has collided.
-
- What the ????
-
- Explanation: The horizontal line in the array has a nujmber indicating a
- part of each block. If you add all these and then move the piece and then
- recalculate, a new id number may have appeared on the horizontal line, eg if
- a long thin block appears. If there is a difference, then the id code is
- subtracted from the 'after' total (if the piece is not one block wide then
- n*id code are subtracted where n is width). This subtraction effectively
- removes the block. If the answer of the processed 'After' is different to
- the 'Before' checksum, it means that an id code apart from the moving
- block one was removed. In other words, putting the new piece in the array
- obscured a previous code, which would signify a collision.
-
- 1. one line before new piece arrives
-
- 01110020 checksum = 5
-
- 2. one line with new piece. this piece has been moving down unobstructed.
- this is its first encounter with other pieces. represented by letter code 3
-
- 01110030 checksum = 6
-
- checksum after - checksum before = 1. Aha. Different. This means a piece
- has arrived. Subtract the id code of the new piece
-
- 1 - 3 = -2
-
- Aha. Not equal to 0. This indicates that a id code was removed when this
- piece arrived. Look at the diagrams and you will see that an id code of
- '2' was removed (7th column)
-
- If anyone needs further explanation, then feel free to email me,
- privately or thru the list.
-
- See ya
-
- --
- t.r.matthews@bradford.ac.uk Founder Member of the 'Irresponsible Club'
- Email me for details on how to join. Must complete an *initiation* *ceremony*
-
-
-